//
//  ZLCollectionReusableView.m
//  TripTogether
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 张磊. All rights reserved.
//

#import "ZLCollectionReusableView.h"


@interface ZLCollectionReusableView ()

@property (nonatomic, strong)UILabel *myLabel;

@property (nonatomic, strong)UIView *myView;

@property (nonatomic, strong)UIButton *btn;

@property (nonatomic, strong)MASConstraint *btnConstraint;

@property (nonatomic, assign)NSInteger index;

@end

@implementation ZLCollectionReusableView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.myView = [[UIView alloc]init];
        self.myView.backgroundColor = [UIColor colorWithRed:0.17 green:0.55 blue:0.61 alpha:1];
        [self addSubview:self.myView];
        
        self.myLabel = [[UILabel alloc]init];
//        self.myLabel.backgroundColor = [UIColor purpleColor];
        [self addSubview:self.myLabel];
        
        [self.myView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.mas_left).offset(10*AUTO_WIDTH);
            make.top.equalTo(self.mas_top).offset(15*AUTO_HEIGHT);
            make.width.equalTo(@(7 * AUTO_WIDTH));
            make.height.equalTo(@(20 * AUTO_HEIGHT));
        }];
        
        [self.myLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.equalTo(self.myView).offset(10*AUTO_WIDTH);
            make.top.equalTo(self.mas_top).offset(10*AUTO_HEIGHT);
            make.width.equalTo(@(220 * AUTO_WIDTH));
            make.height.equalTo(@(30 * AUTO_HEIGHT));
        }];
        self.btn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        self.btn.backgroundColor = [UIColor clearColor];
        [self.btn setTitle:@"更多" forState:(UIControlStateNormal)];
        [self.btn setTitleColor:[UIColor clearColor] forState:(UIControlStateNormal)];
        [self addSubview:self.btn];
        [self masonryBtn];
        self.btn.hidden = NO;
        [self.btn addTarget:self action:@selector(btnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    }
    return self;
}

-(void)setTitleM:(ZLTitleModel *)titleM
{
    self.myLabel.text = titleM.title;
    self.index = titleM.index;
    if ([self.myLabel.text isEqualToString:@"欧洲国家"] || [titleM.title isEqualToString:@"亚洲国家"] || [titleM.title isEqualToString:@"国内城市"]) {
//        NSLog(@"1111111");
        self.btn.hidden = NO;
        }else{
        self.btn.hidden = YES;
//            NSLog(@"222222");
    }
    
    if ([self.myLabel.text isEqualToString:@"欧洲国家"]) {
        self.btn.tag = 1001;
    }else if ([titleM.title isEqualToString:@"亚洲国家"]){
        self.btn.tag = 1002;
    }else if ([titleM.title isEqualToString:@"国内城市"]){
        self.btn.tag = 1003;
    }
}

- (void)masonryBtn
{
        [self.btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right);
        self.btnConstraint = make.width.equalTo(@(80 * AUTO_WIDTH));
        make.bottom.equalTo(self.mas_bottom);
        make.top.equalTo(self).offset(10*AUTO_HEIGHT);
    }];
    
}

- (void)btnAction:(UIButton *)btn
{
    [self.collectionReusableViewDelegate toMoreController:self.btn.tag index:self.index title:self.myLabel.text];
}



@end
